package com.arpost.pages;

import java.io.File;
import java.io.FileOutputStream;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.qualcomm.vuforia.samples.VideoPlayback.R;

public class ShowPhoto extends Activity {

	private final static String TAG = "ShowPhoto";

	ImageView mImageView;

	Button gobackButton;
	Button downloadButton;

	Bitmap mBitmap;
	File mBitmapFile;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.show_photo);

		mBitmap = TakePhoto.BadIdeaBitmapForTransmission;
		mBitmapFile = ShareUtils.saveBitmap(mBitmap, "turtle_rabbit.png");

		gobackButton = (Button) findViewById(R.id.button_show_photo_cancel);
		downloadButton = (Button) findViewById(R.id.button_show_photo_download);

		mImageView = (ImageView) findViewById(R.id.show_picture_view);
		mImageView.setImageBitmap(mBitmap);

		setButtonClickListener();
	}

	private void setButtonClickListener() {
		gobackButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				try {
					mBitmap.recycle();
				} catch (Exception e) {}
				System.exit(0);
			}
		});

		downloadButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				new AlertDialog.Builder(ShowPhoto.this).setTitle("存储成功").setMessage("文件下载到" + mBitmapFile.getAbsolutePath()).setNeutralButton("关闭", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dlg, int sumthin) {
						try {
							dlg.dismiss();
						} catch (Exception e) {
						}
					}
				}).show();
				//Toast.makeText(getApplicationContext(), "文件下载到" + mBitmapFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
			}
		});
	}

	@Override
	public void onBackPressed() {
		mBitmap.recycle();
		super.onBackPressed();
	}
}
